<template>
	<view class="ys">
		<view class="logo" :style="{paddingTop:topStyle}">
			<image src="/static/new/logo.png" mode="widthFix"></image>
		</view>
		<view class="search">
			<view class="inputli" @click="toPage('/pages/index/goods-search')">
				<input type="text" placeholder="搜索商品" disabled>
				<uni-icons type="search" color="#777"></uni-icons>
			</view>

		</view>
		<view class="row">
			<view class="left" :style="{'--h':topStyle}">
				<scroll-view scroll-y="true" class="scroll">
					<view class="left_ul">
						<view @click="navClick(item)" :class="category.id == item.id ? 'left_li active':'left_li'"
							v-for="(item,index) in navlist" :key="index">
							<!-- <view class="imgbox">
									<image :src="item.file_path" mode=""></image>
								</view> -->
							{{item.name}}
						</view>
					</view>
				</scroll-view>
			</view>
			<view class="right" :style="{'--h':topStyle}">
				<view class="list" v-for="(item,index) in goodslist" :key='index'>
					<view class="title">
						{{item.name}}
						<view class="more" @click="toPage(`/pages/classlist/goods?id=${item.id}`)">
							更多 <uni-icons type="right" color="#848484"></uni-icons>
						</view>
					</view>
					<view class="goods">
						<view class="goodsitem" v-for="(goods,index) in item.goods.data" :key='index'
							@click="toPage(`/pages/goodsdetail/index?id=${goods.id}`)">
							<image :src="goods.cover_path" mode=""></image>
							<view class="goodsinfo">
								<view class="name">
									{{goods.name}}
								</view>
								<view class="desc">
									{{goods.sketch}}
								</view>
								<view class="price">
									<text class="pricenum">￥{{goods.price}}</text>
									<text class="sell">已售：{{goods.sales}}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="no-list" v-if="goodslist.length==0">
						- 暂无数据 -
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		getCategory
	} from "@/api/api.js"
	export default {
		data() {
			return {
				navlist: [],
				goodslist: [],
				last_page: 1,
				page: 1,
				category_id: '',
				category: [],
				topStyle: ''
			}
		},
		onLoad() {
			this.getCategory()
			let info = uni.getWindowInfo()
			this.topStyle = info.statusBarHeight + 'px'
		},

		methods: {
			getCategory() {
				getCategory().then(res => {
					if (res.code == 0) {
						this.navlist = res.data
						this.goodslist = this.navlist[0].children
						this.category = this.navlist[0]
					}
				})
			},
			navClick(item, index) {
				this.goodslist = item.children
				this.category = item
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		--bg: '';
		height: 100%;
		min-height: 100vh;
		/* #ifdef H5 */
		min-height: calc(100vh - 50px);
		/* #endif */
		box-sizing: border-box;
		position: relative;
		background-color: #050B18;
		max-width: 500px;

		&::before {
			position: absolute;
			content: '';
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			background-image: var(--bg);
			background-size: cover;
			opacity: .05;
		}
	}

	.logo {
		padding: 0 10px;
		height: 30px;
		display: flex;
		align-items: center;

		image {
			width: 120px;
		}
	}

	.search {
		height: 40px;
		padding: 10px;

		.inputli {
			position: relative;

			input {
				background: rgba(143, 124, 91, 0.2);
				width: 100%;
				font-size: 14px;
				height: 35px;
				line-height: 35px;
				padding: 2px 5px;
				box-sizing: border-box;
				color: rgba(255, 255, 255, 0.4);
				padding-left: 25px;
			}

			text {
				position: absolute;
				left: 5px;
				top: 50%;
				transform: translate(0, -50%);
			}
		}
	}

	.left {
		--h: 0px;
		width: 25%;
		height: calc(100vh - 140px - (var(--h)));
		/* #ifdef MP-WEIXIN */
		height: calc(100vh - 90px - (var(--h)));
		/* #endif */
		position: fixed;
		left: 0;
		bottom: 0;
		/* #ifdef H5 */
		bottom: 50px;
		/* #endif */
		box-sizing: border-box;
		background: #212327;

		uni-scroll-view {
			height: 100%;
		}

		.left_li {
			text-align: center;
			color: #fff;
			font-size: 14px;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			padding: 18px 2px;
			box-sizing: border-box;
			margin-bottom: 10px;

			.imgbox {
				background: #000;
				border-radius: 50%;
				padding: 2px;
				width: 40px;
				height: 40px;
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-bottom: 3px;
			}

			image {
				width: 36px;
				height: 36px;
				border-radius: 50%;
			}
		}

		.active {
			color: #FFD256;
			background: #000;
			border-left: 3px solid #FFD256;
		}
	}

	.right {
		--h: 0px;
		position: relative;
		left: 25%;
		width: 75%;
		overflow: scroll;
		box-sizing: border-box;
		padding: 0 8px;
		padding-top: 20px;
		height: calc(100vh - 140px - var(--h));
		/* #ifdef MP-WEIXIN */
		height: calc(100vh - 90px - var(--h));

		/* #endif */
		.title {
			color: #A96150;
			font-weight: bold;
			padding: 10px;
			box-sizing: border-box;
			font-size: 17px;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 10px;

			.more {
				font-weight: normal;
				font-size: 12px;
				color: #848484;
				display: flex;
				align-items: center;
			}
		}

		.topbanner {
			width: 100%;
			margin-bottom: 10px;
		}

		.goods {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.goodsitem {
				display: flex;
				width: 100%;
				margin-bottom: 10px;
				border-bottom: 1px solid #212327;
				align-items: center;
				position: relative;
				padding: 5px;
				padding-bottom: 15px;
				box-sizing: border-box;

				.num {
					position: absolute;
					right: 0;
					top: 0;
					background: #F23A3A;
					width: 20px;
					height: 20px;
					font-size: 12px;
					color: #fff;
					display: flex;
					align-items: center;
					justify-content: center;
					border-radius: 50%;
				}

				image {
					width: 88px;
					height: 88px;
				}

				.goodsinfo {
					padding: 3px;
					width: calc(100% - 88px);
					height: 88px;
					padding-left: 10px;
					box-sizing: border-box;

					.name {
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						overflow: hidden;
						font-size: 14px;
						color: #fff;

					}

					.desc {
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
						overflow: hidden;
						font-size: 12px;
						height: 36px;
						line-height: 18px;
						color: rgba(140, 140, 140, 0.9);
						margin-top: 5px;
					}

					.price {
						font-size: 12px;
						color: #777;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.sell {
							transform: scale(.9);
						}

						.pricenum {
							color: #FFD256;
							font-size: 14px;
							font-weight: bold;
						}
					}
				}
			}
		}
	}
</style>